package com.dm.cloud.auth.controller.defalut;

import com.dm.cloud.auth.common.mode.AuthUserExtend;
import com.dm.cloud.core.mode.ResultModel;
import com.dm.cloud.core.service.user.CurrentUserService;
import com.dm.cloud.oauthlib.service.anon.HasLogin;
import com.dm.cloud.tkmybatis.service.BaseEntityService;
import com.dm.cloud.tkmybatis.service.EntityBaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.dm.cloud.auth.common.po.AuthUser;
import com.dm.cloud.auth.common.dto.AuthUserDTO;
import com.dm.cloud.auth.common.request.AuthUserSearchRequest;
import com.dm.cloud.auth.service.AuthUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
   * @author hcx
   * @type AuthUserController.java
   * @desc 用户表 AuthUser controller
   */
@RestController
@RequestMapping("/apis/v1/authUser")
@Tag(name =  "用户表  AuthUsercontroller")

public class AuthUserController extends EntityBaseController<AuthUserSearchRequest, AuthUser, AuthUserDTO> {


    @Autowired
    private AuthUserService authUserService;

    @Autowired
    private CurrentUserService currentUserService;

    @Override
    public AuthUser getEntity() {
        return new AuthUser();
    }

    @Override
    public AuthUserDTO getDTO() {
        return new AuthUserDTO();
    }
    @Override
    public BaseEntityService<AuthUserSearchRequest, AuthUser> getService() {
        return authUserService;
    }

    @Override
    public List<FunctionEnum> apiIgnoreFunction(){
        return new ArrayList<FunctionEnum>(){{
            add(FunctionEnum.insert);
            add(FunctionEnum.update);
        }};
    }

    @PostMapping("/inserExtend")
    @Operation(summary = "插入用户及拓展信息,包含角色")
    @HasLogin
    public ResultModel<AuthUserExtend> inserExtend(@RequestBody AuthUserExtend authUserExtend){
        authUserExtend=authUserService.inserExtend(authUserExtend);
        return ResultModel.success(authUserExtend);
    }

    @PostMapping("/updateExtend")
    @Operation(summary = "修改用户及拓展信息,包含角色")
    @HasLogin
    public ResultModel<AuthUserExtend> updateExtend(@RequestBody AuthUserExtend authUserExtend){
        authUserExtend=authUserService.updateExtend(authUserExtend);
        return ResultModel.success(authUserExtend);
    }


//    @PostMapping("/userInfo")
//    @Operation(summary = "用户信息")
//    @HasLogin
//    public Object test(){
//
//        return currentUserService.getCurrentUser();
//    }

}
